package sonia.examples.alm;

import java.awt.Dimension;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.swing.JButton;
import javax.swing.JFrame;

import linearProgramming.LinearProgrammingException;
import alm.ALMException;
import alm.ALMLayout;
import alm.LayoutSpec;
import alm.XTab;
import alm.YTab;


class Bar{
	
}

class Shape extends Bar{
	
}
class Circle extends Shape{
	
}

public class Flow extends JFrame{
	
	public void foo(List<? super Shape> list){
		list.add(new Shape());
	}
	
	public static <T extends Shape> Map<T, String> moo(List a){
		return new HashMap<T, String>();
	}
	
	public static void main(String[] args) throws ALMException, LinearProgrammingException{
		 Flow flow = new Flow();
		 //flow.setVisible(true);
		 
		 Map<Shape, String> m = moo(null);
		 System.out.println();
	}
	
	public Flow() throws ALMException, LinearProgrammingException{
		super("Flow example");
		ALMLayout layout = new ALMLayout();
		LayoutSpec ls = layout.getLayoutSpec();
		
		setLayout(layout);
		setSize(300,80);
		
		YTab topY = ls.getTop();
		YTab bottomY = ls.addYTab();
		XTab currentX = ls.getLeft();
		
		int sum = 0;
		
		for(int i = 0; i < 12; i++){
			JButton button = new JButton("B"+(i+1));
			button.setSize(40,24);
			button.setPreferredSize(new Dimension(40,24));
			sum += 40;
			this.add(button);
			
			if (sum >= 260){
				topY = bottomY;
				bottomY = ls.addYTab();
				currentX = ls.getLeft();
				sum = 0;
			}
			XTab nextX = ls.addXTab();
			ls.addArea(currentX, topY, nextX, bottomY, button);
			currentX = nextX;
		}
	}
	
}
